<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<%@ page import="com.conversationboard.model.*" %>
<%@ page import="com.conversationboard.view.*" %>
<%@ page import="com.conversationboard.config.*" %>
<%@ page import="java.security.*" %>

<%@page pageEncoding="UTF-8"%>
<%@page contentType="text/html;charset=UTF-8"%>

<% 
	Principal principal = request.getUserPrincipal();
	String loginId = principal.getName();
	User user = User.get(loginId);
	request.setAttribute("user", user);
	
	String checked = "";
	String relativeTimes = "";
	String hideThreadInfo = "";
	String hidePolls = "";
	String hideTimeDisplay = "";
	String useTraditionalBookmarks = "";
	String hideLastUpdatedBy = "";
	
	if (user.getPreferences().isShowImages()) {
		checked = "CHECKED";
	}
	
	if (user.getPreferences().isDisplayRelativeTimes()) {
		relativeTimes = "CHECKED";
	}

	if (user.getPreferences().isHideThreadInfo()) {
		hideThreadInfo = "CHECKED";
	}

	if (user.getPreferences().isHidePolls()) {
		hidePolls = "CHECKED";
	}
	
	if (user.getPreferences().isHideTimeDisplay()) {
		hideTimeDisplay = "CHECKED";
	}

	if (user.getPreferences().isUseTraditionalBookmarks()) {
		useTraditionalBookmarks = "CHECKED";
	}

	if (user.getPreferences().isHideLastUpdatedBy()) {
		hideLastUpdatedBy = "CHECKED";
	}

	String key = Confirm.getKey(loginId);
	
%>

<%@page import="com.conversationboard.controller.confirm.Confirm"%>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
		<title>User Preferences</title>
		<link rel="stylesheet" title="Conversation Board" type="text/css" href="<%=Configuration.getInstance().getRoot()%>/Stylesheets/<%=StyleSheets.getStyleSheetFileName(request.getCookies())%>">
	</head>

	<body>
	
		<%= MainMenu.display(principal) %>

		<div class="headingblock">
			<h1>User Preferences: ${user.fullDisplayName}</h1>
		</div>

		<div class="mainblock">		

			<div class="formsection">

				<div class="formsectionlight">
					
					<h2>Password</h2>
				
					<p><a href="Pages/changepassword.jsp">I Want to Change My Password...</a></p>
				</div>

				<br />


				<div class="formsectionlight">

					<form action='<%=Configuration.getInstance().getRoot()%>/PreferencesControllerServlet' method='post'>
						<h2>View Options</h2>
						
						<p><a href="Pages/changestylesheet.jsp">I Want to Change the Way The Site Looks...</a></p>
						<p><a href="<%= Configuration.getInstance().getRoot() %>/CustomiseSiteNewPostsControllerServlet" title="By default, Site New Answers shows you all the latest posts from all boards. If you want to customise which boards are shown when you are logged in, you can do that here.">I Want to Change the Boards Shown on Site New Answers...</a></p>
						<p><a href="<%= Configuration.getInstance().getRoot() %>/Pages/customise-board-shortcuts.jsp" title="If you want to select which board links are displayed on your menu bar, click here.">I Want to Customise the Boards Shown as Shortcuts on my Menu Bar...</a></p>
				
						<p>	
							<label for='checkbox'>Show Images</label>
							<input type='checkbox' name='showimages' value='showimages' <%= checked %> />
						</p>
		
						<p>
							<label for='checkbox'>Display Times as Relative (e.g. 5 minutes ago)</label>
							<input type='checkbox' name='relativetimes' value='relativetimes' <%= relativeTimes %> />
						</p>
						
						<p>
							<label for='checkbox'>Hide Thread Info on New Answers Page</label>
							<input type='checkbox' name='hidethreadinfo' value='hidethreadinfo' <%= hideThreadInfo %> />
						</p>
						
						<p>
							<label for='checkbox'>Hide Polls</label>
							<input type='checkbox' name='hidepolls' value='hidepolls' <%= hidePolls %> />
						</p>
						
						<p>
							<label for='checkbox'>Hide Time Display</label>
							<input type='checkbox' name='hidetimedisplay' value='hidetimedisplay' <%= hideTimeDisplay %> />
						</p>

						<p>
							<label for='checkbox'>Use Traditional Bookmarks (i.e. bookmarks that don't require Javascript enabled)</label>
							<input type='checkbox' name='usetraditionalbookmarks' value='usetraditionalbookmarks' <%= useTraditionalBookmarks %> />
						</p>

						<p>
							<label for='checkbox'>Hide Last Updated By on Threads</label>
							<input type='checkbox' name='displaylastupdatedby' value='displaylastupdatedby' <%= hideLastUpdatedBy %> />
						</p>
						
						<p>
							Time Zone: <%= TimeZoneDropDownDisplay.display(user) %>
						</p>
		
						<p>	
						 	<input type="submit" value="     Update My Preferences     " />
						</p>
					</form>
					
				</div>

				<br />
				
				<div class="formsectionlight">
					<h2>Profile</h2>
					<p><a href="Pages/editprofile.jsp">I Want to Edit My Profile...</a></p>
					
					<c:if test="${config.allowChangeOfUserName}">
						<form class="formsection" action="<%= Configuration.getInstance().getRoot() %>/UpdateDisplayNameControllerServlet" method="post">
							<%= key %>						
							<input name='loginid' value="${user.loginId}" type='hidden' />
							Change Display Name: <input name='displayname' class='smalltextbox' type='text' size="35" />
							<input type='submit' value='     OK     ' />
							
							<p>Your original display name will be displayed in brackets. If you choose too long a name, your new display name
						       will be truncated in order that your original display name is still visible.</p>
						       
						    <p>Enter nothing in the dialog and click 'OK' to revert to your original display name.</p>
						</form>			
					</c:if>
				</div>
				
				<br />
	
				<div class="formsectionlight">

					<h2>Board Email Subscriptions</h2>
						
					<p>You are subscribed to the following boards. Click "unsubscribe" to stop yourself receiving a daily
					   email for the listed board.</p>
				
					<table class="table">
					<tr class="header">
						<th class="cell">Subscription</th>
						<th class="cell">Unsubscribe</th>
					</tr>

					<c:forEach var="subscription" items="${subscriptions}">
			
						<tr class="row">
							<td class="cell">${subscription.name}</td>
							<td class="cell">
								<form action="UnsubscribeControllerServlet" method="post">
									<%= key %>
									<input type="hidden" name="boardid" value="${subscription.boardId}" />
	 								<input type="submit" value="Unsubscribe" />
								</form>
							</td>
						</tr>
					
					</c:forEach>
				</table>
				
				</div>
			</div>
		</div>

		<!--<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>-->
		<!--<script type="text/javascript">_uacct = "UA-1148679-1";urchinTracker();</script>--> 

	</body>
	
</html>